package org.hq.web.utils;

/**
 * 返回结果给客户端
 * @param <T>
 */
public class R<T> {
    private Integer code;
    private String msg;
    private T data;
    private static final String DEFFAULT_SUCCESS_MSG = "succecc";
    private static final String DEFFAULT_FAILED_MSG = "error";
    private static final Integer DEFFAULT_SUCCESS_CODE = 200;
    private static final Integer DEFFAULT_FAILED_CODE = 500;


    public R() {
    }

    public R(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public R(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
    public static <T> R<T> no(T data) {
      return new R<>(DEFFAULT_FAILED_CODE,DEFFAULT_FAILED_MSG,data);
    }
    public static <T> R<T> no() {
        return no(null);
    }
    public static <T> R<T> ok(T data) {
        return new R<>(DEFFAULT_SUCCESS_CODE,DEFFAULT_SUCCESS_MSG,data);
    }
    public static <T> R<T> ok() {
        return ok(null);
    }
}
